local blaze = require "blaze"
local game = require "club.threecard.sudoku"
local gamelib = require "club.threecard.gamelib"
local const = game.util.const

local log = blaze.logging.get("settlement")

local M = {}

M.state = {
    winner = 0,
    players = {},
    statistics = {}
}

M.actions = {
    continue = function(store, state, args)
        local _, roomconfig = game.roomcache.get(gamelib.game_scene.room_config_id)
        if roomconfig.mode == "火拼" then
            gamelib.game_scene.entrances.intent = "继续火拼"
            gamelib.game_scene.leave()
        elseif roomconfig.mode == "挑战" then
            gamelib.game_scene.entrances.intent = "继续挑战"
            gamelib.game_scene.leave()
        elseif roomconfig.mode == "休闲" then
            game.kbe.player():ready(1)
            game.router.back()
        end
    end,

    backward = function(store, state, args)
        gamelib.game_scene.leave()
    end
}

M.mutations = {
    -- 结算
    -- args.winner 获胜玩家编号
    -- args.players SudokuPlayer列表
    -- args.statistics 结算信息列表
    settle = function(store, state, args)
        state.winner = args.winner
        state.players = args.players
        state.statistics = args.statistics
        store.emit("结算", args)
    end
}

return M